package com.yy.utils;

import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yy.utils.HttpUtil;

public class AccessToken {
    private static Gson gson = new GsonBuilder().setPrettyPrinting().create();

    /**
     * 使用前请先下载工具包
     * https://open.iot.10086.cn/ai/code/javaUtil.zip
     */
    public static String accessToken(String aiKey,String secretKey) {
        //服务地址

        String path = "http://ai.heclouds.com:9090/v1/user/app/accessToken?aiKey=" + aiKey + "&secretKey=" + secretKey;
        try {
            //调用
            String result = HttpUtil.get(path, null);
//            System.out.println("result:" + result);
            Map map = gson.fromJson(result, Map.class);
            Object data = map.get("data");
            return  gson.fromJson(gson.toJson(data), Map.class).get("accessToken").toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

}
